﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using FluentValidation.Attributes;
using Giant.Admin.Validators.Users;
using Giant.Web.Framework;
using Giant.Web.Framework.Mvc;
using Giant.Core.Domain.Common;

namespace Giant.Admin.Models.Users
{
    [Validator(typeof(UserValidator))]
    public partial class UserModel : BaseEntityModel
    {
        public UserModel()
        {
            this.AvailableTimeZones = new List<SelectListItem>();
            this.SendEmail = new SendEmailModel() { SendImmediately = true };

            this.SelectedUserRoleIds= new List<int>();
            this.AvailableUserRoles = new List<SelectListItem>();

            this.AssociatedExternalAuthRecords = new List<AssociatedExternalAuthModel>();
            this.UserAttributes = new List<UserAttributeModel>();
            this.AvailableNewsletterSubscriptionSites = new List<SiteModel>();
        }

        public bool AllowUsersToChangeUsernames { get; set; }
        public bool UsernamesEnabled { get; set; }

        [AppResourceDisplayName("Admin.Users.Users.Fields.Username")]
        [AllowHtml]
        public string Username { get; set; }

        [AppResourceDisplayName("Admin.Users.Users.Fields.Email")]
        [AllowHtml]
        public string Email { get; set; }

        [AppResourceDisplayName("Admin.Users.Users.Fields.Password")]
        [AllowHtml]
        public string Password { get; set; }

        //form fields & properties
        public bool GenderEnabled { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.Gender")]
        public string Gender { get; set; }

        [AppResourceDisplayName("Admin.Users.Users.Fields.FirstName")]
        [AllowHtml]
        public string FirstName { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.LastName")]
        [AllowHtml]
        public string LastName { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.FullName")]
        public string FullName { get; set; }
        
        public bool DateOfBirthEnabled { get; set; }
        [UIHint("DateNullable")]
        [AppResourceDisplayName("Admin.Users.Users.Fields.DateOfBirth")]
        public DateTime? DateOfBirth { get; set; }
        
        public bool PhoneEnabled { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.Phone")]
        [AllowHtml]
        public string Phone { get; set; }

        public List<UserAttributeModel> UserAttributes { get; set; }

        

        [AppResourceDisplayName("Admin.Users.Users.Fields.AdminComment")]
        [AllowHtml]
        public string AdminComment { get; set; }
     
        [AppResourceDisplayName("Admin.Users.Users.Fields.Active")]
        public bool Active { get; set; }

        //time zone
        [AppResourceDisplayName("Admin.Users.Users.Fields.TimeZoneId")]
        [AllowHtml]
        public string TimeZoneId { get; set; }

        public bool AllowUsersToSetTimeZone { get; set; }

        public IList<SelectListItem> AvailableTimeZones { get; set; }


        //registration date
        [AppResourceDisplayName("Admin.Users.Users.Fields.CreatedOn")]
        public DateTime CreatedOn { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.LastActivityDate")]
        public DateTime LastActivityDate { get; set; }

        //IP adderss
        [AppResourceDisplayName("Admin.Users.Users.Fields.IPAddress")]
        public string LastIpAddress { get; set; }


        [AppResourceDisplayName("Admin.Users.Users.Fields.LastVisitedPage")]
        public string LastVisitedPage { get; set; }


        //user roles
        [AppResourceDisplayName("Admin.Users.Users.Fields.UserRoles")]
        public string UserRoleNames { get; set; }
        public List<SelectListItem> AvailableUserRoles { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.UserRoles")]
        [UIHint("MultiSelect")]
        public IList<int> SelectedUserRoleIds { get; set; }


        //newsletter subscriptions (per site)
        [AppResourceDisplayName("Admin.Users.Users.Fields.Newsletter")]
        public List<SiteModel> AvailableNewsletterSubscriptionSites { get; set; }
        [AppResourceDisplayName("Admin.Users.Users.Fields.Newsletter")]
        public int[] SelectedNewsletterSubscriptionSiteIds { get; set; }


        //send email model
        public SendEmailModel SendEmail { get; set; }
        //send the welcome message
        public bool AllowSendingOfWelcomeMessage { get; set; }
        //re-send the activation message
        public bool AllowReSendingOfActivationMessage { get; set; }

        [AppResourceDisplayName("Admin.Users.Users.AssociatedExternalAuth")]
        public IList<AssociatedExternalAuthModel> AssociatedExternalAuthRecords { get; set; }


        #region Nested classes

        public partial class SiteModel : BaseEntityModel
        {
            public string Name { get; set; }
        }

        public partial class AssociatedExternalAuthModel : BaseEntityModel
        {
            [AppResourceDisplayName("Admin.Users.Users.AssociatedExternalAuth.Fields.Email")]
            public string Email { get; set; }

            [AppResourceDisplayName("Admin.Users.Users.AssociatedExternalAuth.Fields.ExternalIdentifier")]
            public string ExternalIdentifier { get; set; }

            [AppResourceDisplayName("Admin.Users.Users.AssociatedExternalAuth.Fields.AuthMethodName")]
            public string AuthMethodName { get; set; }
        }

        public partial class SendEmailModel : BaseModel
        {
            [AppResourceDisplayName("Admin.Users.Users.SendEmail.Subject")]
            [AllowHtml]
            public string Subject { get; set; }

            [AppResourceDisplayName("Admin.Users.Users.SendEmail.Body")]
            [AllowHtml]
            public string Body { get; set; }

            [AppResourceDisplayName("Admin.Users.Users.SendEmail.SendImmediately")]
            public bool SendImmediately { get; set; }

            [AppResourceDisplayName("Admin.Users.Users.SendEmail.DontSendBeforeDate")]
            [UIHint("DateTimeNullable")]
            public DateTime? DontSendBeforeDate { get; set; }
        }

        public partial class ActivityLogModel : BaseEntityModel
        {
            [AppResourceDisplayName("Admin.Users.Users.ActivityLog.ActivityLogType")]
            public string ActivityLogTypeName { get; set; }
            [AppResourceDisplayName("Admin.Users.Users.ActivityLog.Comment")]
            public string Comment { get; set; }
            [AppResourceDisplayName("Admin.Users.Users.ActivityLog.CreatedOn")]
            public DateTime CreatedOn { get; set; }
            [AppResourceDisplayName("Admin.Users.Users.ActivityLog.IpAddress")]
            public string IpAddress { get; set; }
        }

        public partial class UserAttributeModel : BaseEntityModel
        {
            public UserAttributeModel()
            {
                Values = new List<UserAttributeValueModel>();
            }

            public string Name { get; set; }

            public bool IsRequired { get; set; }

            /// <summary>
            /// Default value for textboxes
            /// </summary>
            public string DefaultValue { get; set; }

            public AttributeControlType AttributeControlType { get; set; }

            public IList<UserAttributeValueModel> Values { get; set; }

        }

        public partial class UserAttributeValueModel : BaseEntityModel
        {
            public string Name { get; set; }

            public bool IsPreSelected { get; set; }
        }

        #endregion
    }
}